package com.example.servicetest;

import android.annotation.SuppressLint;
import android.app.IntentService;
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;

public class MyService extends Service {

    private DownloadBinder mBinder = new DownloadBinder();

    public MyService() {
    }

    @Override
    public IBinder onBind(Intent intent) {

        return mBinder;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d("MyService","onCreate");
        Notification notification = new NotificationCompat.Builder(this)
                .setContentText("This is a content text")
                .setContentTitle("This is a content title")
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.mipmap.ic_launcher)
                .build();
        startForeground(1,notification);

    }
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d("MyService","onStartCommand");
        return super.onStartCommand(intent, flags, startId);
    }

    @SuppressLint("WrongConstant")
    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    public void onDestroy() {
        stopForeground(1);
        super.onDestroy();
        Log.d("MyService","onDestroy");
    }


    class DownloadBinder extends Binder{
        public void startDownload(){
            Log.d("MyService","StartDownload executed");
        }

        public int getProcess(){
            Log.d("MyService","getProgress executed");
            return 0;
        }
    }
}
